wayland: Keep hotspot when changing cursors
authorMatthias Clasen <mclasen@redhat.com>
Thu, 21 Mar 2013 01:47:12 +0000 (21:47 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 21 Mar 2013 02:21:15 +0000 (22:21 -0400)
We need to pass the delta between the old and new hotspot
when attaching the new cursor surface, to keep the hotspot
at the same position. We can't deal with this in the compositor,
since the set_cursor call already overwrites the old hotspot,
so the information is lost by the time the attach happens.
Unfortunately, we can't query the initial hotspot from
the compositor, so the first cursor change will make the
hotspot jump.
https://bugzilla.gnome.org/show_bug.cgi?id=695512

gdk/wayland/gdkdevice-wayland.c

index e7776c86c8a2ed8922630851154eec32a5eb912d..24176e98f9d21630463cfb19780d1c3f9698613b 100644 (file)
@@ -76,6 +76,7 @@ struct _GdkWaylandDeviceData
   GdkWaylandSelectionOffer *selection_offer_out;
 
   struct wl_surface *pointer_surface;
+  int hotspot_x, hotspot_y;
 };
 
 struct _GdkWaylandDevice
@@ -172,10 +173,13 @@ gdk_wayland_device_set_window_cursor (GdkDevice *device,
                          _gdk_wayland_display_get_serial (wayland_display),
                          wd->pointer_surface,
                          x, y);
-  wl_surface_attach (wd->pointer_surface, buffer, 0, 0);
+  wl_surface_attach (wd->pointer_surface, buffer, wd->hotspot_x - x, wd->hotspot_y - y);
   wl_surface_damage (wd->pointer_surface,  0, 0, w, h);
   wl_surface_commit(wd->pointer_surface);
 
+  wd->hotspot_x = x;
+  wd->hotspot_y = y;
+
   g_object_unref (cursor);
 }